<template>
	<!-- 抵扣设置 -->
	<view class="d_wp">
		<view class="d_li d_old">
			<text>原抵扣比列：</text><text class="d_color">{{oldproportion}}%</text>
		</view>
		<view class="d_li">
			<text>现抵扣比列：</text><input class="d_color" type="number" placeholder="请输入现抵扣比例" v-model="proportion" />
			<view class="d_message d_color">
				请输入0-100整数比例。
			</view>
		</view>

		<button class="fbt" @click="sumbit">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				oldproportion: 0,
				proportion: '',
			}
		},
		onLoad() {
			this.getInfo();
		},
		methods: {
			sumbit() {
				if (this.proportion === '') {
					this.$api.msg('请输入抵扣比例');
					return
				}
				if (this.proportion.indexOf('.')!=-1||this.proportion*1<0||this.proportion*1>100) {
					this.$api.msg('抵扣比例为0-100整数');
					return
				}
				this.$axios('info/setDeduction', 'POST', 'supplier',{rate:this.proportion}).then(res => {
					if (res.data.code == 200) {
						this.$api.msg('提交成功');
					}
				})
			},
			getInfo() {
				this.$axios('info/getDeduction', 'POST', 'supplier').then(res => {
					if (res.data.code == 200) {
						this.oldproportion = res.data.data;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f2f2f2;
		color: $font-color-dark;
	}

	.d_li {
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		padding: 0 20upx 20upx;
	}

	.d_old {
		padding-top: 30upx;
	}

	.d_color {
		color: #FF0000;
		font-size: 28upx;
	}

	.d_message {
		font-size: 24upx;
		line-height: 40upx;
		width: 100%;
	}
</style>
